package actions;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.*;

import views.FileView;
import org.eclipse.ui.*;



import views.errorView;


public class OpenAction extends Action {
	private IWorkbenchWindow window;
	
	
	public OpenAction(IWorkbenchWindow window)
	{
		this.window=window;
		this.setText("Open");
		
	}
	
	public void run()
	{
		FileDialog fd=new FileDialog(Display.getCurrent().getActiveShell(),SWT.OK);
		fd.setText("Open");
		
		fd.setFilterPath("D:/");
		String []filterExt={"*.bpel","*.bpelex","*.wsdl","*.xml"};
		fd.setFilterExtensions(filterExt);
		fd.open();
		String str=fd.getFileName();
		
		FileView.addTreeChild(str);
		
		if(window != null) {	
			try {
				window.getActivePage().hideView(window.getActivePage().findView(FileView.ID));
				window.getActivePage().showView(FileView.ID);
				
			} catch (PartInitException e) {
				MessageDialog.openError(window.getShell(), "Error", "Error opening view:" + e.getMessage());
			}
		}
		
		
		
	}

}
